<template>
	<view class="remine-thing">
		<!-- <liuyuno-tabs :tabData="tabs" :defaultIndex="defaultIndex" @tabClick='tabClick' @confirm='confirmDate' @rest='restSearch'/> -->
		<nav-tab  :defaultIndex='defaultIndex' @tapChange='tapChange' @attedanceChange='attedanceChange' @workChange='workChange' :attedanceOptions='attedanceOptions' 
				:workGroupeOptions='workGroupeOptions':tapsData='tapsData' :periodValue ='nowPeriod' :periodIndex='periodIndex'></nav-tab>
		<view v-if="remainThingData.length==0" class="data-tip">没有待审核的内容</view>
		<view class="lay-remain">
			<remainThingCard :workInfon='item.data.hvo.teamproperty'  :isShowBtn="isShowBtn" :propMsg='item.message' :rusult='item.data.hvo.approvenote'
				 class="remain-card"  v-for="(item,index) in remainThingData" :key='index' type="kaoqin" :status="item.data.hvo.approvestatus"
				@handleClick='handleClick(item)'></remainThingCard>
		</view>
	</view>
</template>

<script>
	import service from '../../common/service/new_file.js'
	import apiData from '../../common/utils/apiData.js'
	import utils from '../../common/utils/utils.js'
	export default {
		data() {
			return {
				attedanceOptions:[],
				workGroupeOptions:[],
				searchValue:'',
				input:'',
				periodIndex:0,
				remainThingData: [],
				defaultIndex:0,//tap默认的选择,index基于传过去的数组
				isShowBtn: true,
				tapsData:[{value:'未审核',num:0},{value:'已审核',num:0}],
				isExamine:0,//是否审批
				nowPeriod:'考勤',
				ischeck:'N',
				nowServiceperiod:'',
				nowServiceWork:''
			};
		},
		methods: {
			tapChange(value){
				this.remainThingData=[]
				if(value.index ==0){
					this.ischeck = 'N'
					this.isExamine = 0
					this.getAttendList(this.ischeck)
				}else if(value.index ==1){
					this.ischeck = 'Y'
					this.isExamine = 1
					this.getAttendList(this.ischeck)
				}
			},
			attedanceChange(value){
				this.nowServiceperiod = value.pk_period_b
				this.nowPeriod = value.yearmth
				this.getAttendList(this.ischeck)
			},
			workChange(value){
				this.nowServiceWork = value
				// console.log(value)
				this.getAttendList(this.ischeck)
			},
			restSearch(){
				
			},
			confirmDate(value){
				if(this.defaultIndex ==0){
					this.getAttendList(this.ischeck)
				}else if(this.defaultIndex ==1){
					this.getAttendList(this.ischeck)
				}
			},
			handleClick(item) {
				let month = item.message.split('[')[1].split(']')[0]
				uni.navigateTo({
					url: './attendanceExamine?item=' + JSON.stringify(item.data) + '&month=' + month+'&isExamine=' + this.isExamine+'&msg='+item.message
				})
			},
			// tabClick(value) {
			// 	this.defaultIndex = value
			// 	if (value == '0') {
			// 		this.remainThingData=[]
			// 		this.getAttendList(this.ischeck)
			// 		this.isShowBtn = true
			// 		this.isExamine = 1
			// 	} else if (value == '1') {
			// 		this.remainThingData=[]
			// 		this.getAttendList(this.ischeck)
			// 		this.isShowBtn = false
			// 		this.isExamine = 2
			// 	}
			// },
			getAttendList(ischeck) {
				let _this = this
				let initObj = {
					pk_team:this.nowServiceWork,//班组
					pk_period_b:this.nowServiceperiod//考勤期间
				}
				let data = apiData.setAtedanceList('HAAP',ischeck,initObj)
				service.common(data, {
					success: function(res) {
						if(res.data.VALUES.length==0){
							uni.showToast({
								icon:'none',
								title:'未查询到数据'
							})
						}
						_this.remainThingData = res.data.VALUES
						if(_this.ischeck=='N'){
							_this.tapsData[0].num = _this.remainThingData.length
						}else if(_this.ischeck=='Y'){
							// _this.tapsData[1].num = _this.remainThingData.length
						}
						// uni.setStorageSync('remineData',JSON.stringify(res.data.VALUES))
					},
					fail:function(res){
						console.log(res)
					}
				})
			},
			getWorkGroup(){
				let _this = this
				let data = apiData.getWorkGroup("hrhateam")
				service.common(data, {
					success: function(res) {
						let objValue = res.data.VALUES[0]
						let newArr = []
						for (let key in objValue) {
							newArr.push({
								value:key,
								label:objValue[key]
							})
						}
						newArr.unshift({
							value:'',
							label:'全部'
						})
						_this.workGroupeOptions = newArr
					},
					fail:function(res){
						console.log(res)
					}
				})
			},
			getPeriod(){
				let _this = this
				let data = apiData.getWorkGroup("kqqj")
				service.common(data, {
					success: function(res) {
						let newArr = [];
						let worKPeriodOption = res.data.VALUES;
						let month = new Date().getMonth() + 1;
						month = month < 10 ? '0' + month : month;
						let nowTime = new Date().getFullYear() + '-' + month;
						worKPeriodOption.forEach((item, index) => {
							if (item.yearmth == nowTime) {
								newArr.push(item);
								_this.periodIndex = index
							}
						});
						// _this.nowPeriod = newArr[0].yearmth
						// _this.nowServiceperiod =  newArr[0].pk_period_b
						worKPeriodOption.unshift({
							pk_period_b:'',
							yearmth:'全部'
						})
						_this.attedanceOptions =worKPeriodOption
					},
					fail:function(res){
						console.log(res)
					}
				})
			},
		},
		onLoad() {
			this.getAttendList(this.ischeck)
			this.getPeriod()
			this.getWorkGroup()
		},
		onPullDownRefresh() {
			let initObj = {
				pk_team:this.nowServiceWork,//班组
				pk_period_b:this.nowServiceperiod//考勤期间
			}
			this.getAttendList(this.ischeck,initObj)
		},
		onReady() {
			
		}
	}
</script>

<style lang="scss" scoped>
	.lay-remain {
		padding-top: 80rpx;
		padding-bottom: 40rpx;
		.remain-card {
			background: red;
			margin: 30rpx 30rpx;
		}
	}
	.data-tip {
		text-align: center;
		color: #949494;
		padding-top: 210rpx;
		font-size: 28rpx;
	}
</style>
